#include "stdafx.h"
#include "file.h"
#include "main_generator.h"
#include "report.h"

int main(int argc, char *argv[]) {

	char *source = 0, *pre_processed_source = 0;
	CFG *cfg ;
	const char *report_file = "report.txt";
	const char *source_file = "sample.c";
	MyFile *myfile = 0;
	bool parsed = false;

	if(argc != 3)
		myfile = 0;
	else {
		report_file = argv[2];
		source_file = argv[1];
		myfile = file_open(source_file);
	}


	if(myfile) {
		source = (char *)malloc(sizeof(char)*(myfile->file_size+1));
		memset(source, 0, myfile->file_size+1);
		file_read(source, myfile);
		file_close(myfile);
	}

	pre_processed_source = pre_processor(source);

	cfg = make_cfg();
	parsed = parse(cfg, pre_processed_source);
	if(!parsed)
		return 0;

	report(cfg, report_file);
	if(cfg) destroy_cfg(cfg);

	if(source) free(source);

	return 0;
}
